<template>
	<view class="discovery tn-safe-area-inset-bottom">

		<!-- 顶部自定义导航 -->
		<!-- <tn-nav-bar :isBack="false" :bottomShadow="false" backgroundColor="#FFFFFF99">
			<view class="custom-nav tn-flex tn-flex-col-center tn-flex-row-left">
				<view class="custom-nav__back">
					<text class="tn-icon-discover tn-color-cat" style="font-size: 50rpx;"
						@click="tn('/discoveryPages/edit')">
					</text>
					<text class="tn-icon-team tn-color-cat tn-padding-left" style="font-size: 50rpx;"
						@click="tn('/discoveryPages/partner')">
					</text>
				</view>
			</view>
		</tn-nav-bar> -->


		<swiper class="card-swiper" @click="tn('')" :circular="true" :autoplay="true" duration="0" interval="5000"
			@change="cardSwiper">
			<swiper-item v-for="(item,index) in swiperList" :key="index" :class="cardCur==index?'cur':''">
				<view class="swiper-item image-banner">
					<image :src="item.pic" mode="aspectFill"></image>
				</view>

				<view class="swiper-item-text">
					<view class="tn-padding swiper-item-title">
						<view class="tn-text-bold" style="font-size: 40rpx; color: #fff;">{{item.title}}</view>
						<view class="tn-padding-top" style="font-size: 25rpx;color: #fff;">
							<!-- {{item.content}} -->
							<rich-text :nodes="item.content"></rich-text>
						</view>
					</view>
				</view>
			</swiper-item>
		</swiper>
		<view class="indication">
			<block v-for="(item,index) in swiperList" :key="index">
				<view class="spot" :class="cardCur==index?'active':''"></view>
			</block>
		</view>

		<!-- 方式5，图片形式 start-->
		<view class="tn-flex tn-flex-wrap tn-padding-top home-shadow">
			<block v-for="(item, index) in icons" :key="index">
				<view class="tn-margin-bottom tn-margin-top-sm" style="width: 25%;" @click="tn(item.url)">
					<view class="tn-flex tn-flex-direction-column tn-flex-row-center tn-flex-col-center">
						<view class="icon5__item--icon tn-flex tn-flex-row-center tn-flex-col-center"
							:style="'background-image:url('+ item.pic +');background-size:100% 100%;background-size: cover;'">
						</view>
						<view class="tn-text-center" style="color: #a79c8e;">
							<text class="tn-text-ellipsis">{{ item.title }}</text>
						</view>
					</view>
				</view>
			</block>
		</view>
		<!-- 方式5 end-->

		<!-- <backTop :scrollTop="scrollTop"></backTop> -->

		<view>
			<view class="tn-margin-top">
				<view class="nav_title--wrap">
					<view class="nav_title">
						<text class="tn-icon-like tn-padding-right-sm"></text>
						婚 礼 倒 计 时
						<text class="tn-icon-like tn-padding-left-sm"></text>
					</view>
				</view>
			</view>

			<view class="date-backgroup tn-margin-bottom">
				<tn-count-down class="coutDown" :timestamp="countTime" separator="cn" :showDays="true" :showHours="true"
					:showMinutes="true" :showSeconds="true" :fontSize="50" :separatorSize="50">
				</tn-count-down>
				<text class="text">Always miss you, although we cant share every minute.</text>
			</view>
		</view>

		<!-- 边距间隔 -->
		<view class="tn-strip-bottom"></view>

		<view>
			<view class="tn-margin-top">
				<view class="nav_title--wrap">
					<view class="nav_title ">
						<text class="tn-icon-time tn-padding-right-sm"></text>
						婚 礼 日 期
						<text class="tn-icon-time tn-padding-left-sm"></text>
					</view>
				</view>
			</view>

			<view class="content-backgroup">
				<image :src='dateImg' mode='widthFix' class='backgroud-image'></image>
			</view>
		</view>

		<!-- 边距间隔 -->
		<view class="tn-strip-bottom"></view>

		<view v-if="weddingVideo!=''">
			<view class="tn-margin-top">
				<view class="nav_title--wrap">
					<view class="nav_title ">
						<text class="tn-icon-live-stream tn-padding-right-sm"></text>
						婚 礼 预 告
						<text class="tn-icon-live-stream tn-padding-left-sm"></text>
					</view>
				</view>
			</view>

			<view class="content-backgroup tn-margin-bottom-xl">
				<video :src="weddingVideo"
				controls
				objectFit='cover'
				show-mute-btn="true" 
				class='video-backgroup'
				@play="play"
				></video>
			</view>
		</view>

	</view>
</template>

<script>
	import template_page_mixin from '@/uni_modules/tuniao-ui/libs/mixin/template_page_mixin.js';
	import backTop from '@/components/back-top.vue';
	import {weddingConfig,listWeddingPage} from "@/api/common/api";
	export default {
		name: 'home',
		mixins: [template_page_mixin],
		components: {
			backTop
		},
		data() {
			return {
				scrollTop: 0,
				cardCur: 0,
				swiperList: [],
				/* tabs*/
				icons: [],
				countTime:'',
				dateImg:'',
				weddingVideo: ''
			}
		},
		onLoad() {
			this.initSwiper();
			this.initicons();
			this.initDateImg();
			this.initCountTime();
			this.initVideo();
		},
		methods: {
			play(){
				getApp().globalData.audio.pause();
			},
			// 跳转
			tn(e) {
				uni.navigateTo({
					url: e,
				});
			},
			initVideo(){
				listWeddingPage(3).then(res => {
					this.weddingVideo=res.data[0].url;
				})
			},
			initDateImg(){
				listWeddingPage(5).then(res => {
					this.dateImg=res.data[0].url;
				})
			},
			initicons(){
				listWeddingPage(2).then(res => {
					this.icons=res.data;
				})
			},
			initSwiper(){
				listWeddingPage(1).then(res => {
					this.swiperList=res.data;
				})
			},
			initCountTime(){
				weddingConfig().then(res => {
					let weddingDate = res.data.weddingDate
					const date = new Date(weddingDate.replace(/-/g,'/'));
					console.log("date",date)
					console.log("date.time",date.getTime())
					const now = new Date();
					console.log("now",now)
					console.log("now.time",now.getTime())
					const diff = date.getTime() - now.getTime();
					console.log("diff",diff)
					const seconds = diff / 1000;
					console.log("seconds",seconds)
					this.countTime=seconds;
				})
			},
			cardSwiper(e) {
				this.cardCur = e.detail.current
			},
		}
	}
</script>

<style lang="scss" scoped>
	.discovery {
		max-height: 100vh;
	}

	/* 底部安全边距 start*/
	.tn-safe-area-inset-bottom {
		min-height: 120rpx;
		height: calc(140rpx + env(safe-area-inset-bottom) / 2);
		height: calc(140rpx + constant(safe-area-inset-bottom));
	}

	/* 自定义导航栏内容 start */
	.custom-nav {
		height: 100%;

		&__back {
			margin-left: 30rpx;
			margin-top: 5rpx;
			font-size: 40rpx;
			flex-basis: 5%;
			width: 100rpx;
			position: absolute;
		}
	}

	/* 自定义导航栏内容 end */

	/* 图标容器5 start */
	.icon5 {
		&__item {
			// width: 30%;
			background-color: #FFFFFF;
			border-radius: 10rpx;
			padding: 0rpx;
			margin: 0rpx;
			transform: scale(1);
			transition: transform 0.3s linear;
			transform-origin: center center;

			&--icon {
				width: 96rpx;
				height: 96rpx;
				border-radius: 50%;
				margin-bottom: 18rpx;
				position: relative;
				z-index: 1;
			}
		}
	}

	/* 轮播视觉差 start */
	.card-swiper {
		height: 800rpx !important;
	}

	.card-swiper swiper-item {
		width: 750rpx !important;
		left: 0rpx;
		box-sizing: border-box;
		padding: 0;
		overflow: initial;
	}

	.card-swiper swiper-item .swiper-item {
		width: 100%;
		display: block;
		height: 100%;
		transform: scale(1);
		transition: all 0.2s ease-in 0s;
		overflow: hidden;
	}

	.card-swiper swiper-item.cur .swiper-item {
		transform: none;
		transition: all 0.2s ease-in 0s;
	}

	.card-swiper swiper-item .swiper-item-text {
		// background-color: rgba(0, 0, 0, 0.7);
		background-image: linear-gradient(0deg, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.05));
		margin-top: -260rpx;
		width: 100%;
		display: block;
		height: 50%;
		// border-radius: 10rpx;
		transform: translate(0rpx, 0rpx) scale(1);
		transition: all 0.6s ease 0s;
		overflow: hidden;
	}

	.card-swiper swiper-item.cur .swiper-item-text {
		// background-color: rgba(0, 0, 0, 0.7);
		background-image: linear-gradient(0deg, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.04));
		margin-top: -260rpx;
		width: 100%;
		transform: translate(0rpx, 0rpx) scale(1);
		transition: all 0.6s ease 0s;
	}


	.card-swiper swiper-item .swiper-item-title {
		transform: translate(50rpx, 0rpx) scale(0.9);
		transition: all 0.6s ease 0s;
		overflow: hidden;
	}

	.card-swiper swiper-item.cur .swiper-item-title {
		transform: translate(0rpx, 0rpx) scale(1);
		transition: all 0.6s ease 0s;
	}

	.image-banner {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.image-banner image {
		width: 100%;
		height: 100%;
	}

	/* 轮播指示点 start*/
	.indication {
		z-index: 9999;
		width: 100%;
		height: 36rpx;
		position: absolute;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;
	}

	.spot {
		background-color: #FFFFFF;
		opacity: 0.6;
		width: 10rpx;
		height: 10rpx;
		border-radius: 20rpx;
		top: -60rpx;
		margin: 0 8rpx !important;
		position: relative;
	}

	.spot.active {
		opacity: 1;
		width: 30rpx;
		background-color: #FFFFFF;
	}

	/* 用户头像 start */
	.logo-image {
		width: 40rpx;
		height: 40rpx;
		position: relative;
	}

	.logo-pic {
		background-size: cover;
		background-repeat: no-repeat;
		// background-attachment:fixed;
		background-position: top;
		border: 1rpx solid rgba(255, 255, 255, 0.05);
		// box-shadow: 0rpx 0rpx 80rpx 0rpx rgba(0, 0, 0, 0.15);
		border-radius: 50%;
		overflow: hidden;
	}

	/* 标题 start */
	.nav_title {
		-webkit-background-clip: text;
		color: #a79c8e;

		&--wrap {
			position: relative;
			display: flex;
			height: 120rpx;
			font-size: 46rpx;
			align-items: center;
			justify-content: center;
			font-weight: bold;
			background-image: url(https://tnuiimage.tnkjapp.com/title_bg/title44.png);
			background-size: cover;
		}
	}

	/* 标题 end */

	/* 内容图 start */
	.content-backgroup {
		z-index: -1;

		.backgroud-image {
			border-radius: 15rpx;
			width: 100%;
		}

		.video-backgroup {
			width: 100%;
			margin-bottom: 30px;
		}
	}

	/* 内容图 end */


	.date-backgroup {
		text-align: center;
		background-image: url(https://tnuiimage.tnkjapp.com/title_bg/title44.png);
		height: 150px;
		display: grid;

		.coutDown {
			// line-height: 100px;
			margin: 40px 0 20px 0;
		}

		.text {
			line-height: 20px;
			margin: 10px 0 10px 0;
			color: #f1bbba;
		}
	}
</style>
